package User;

import book.Book;
import book.Libary;
import utils.AnalyingBorrowBook;
import utils.AnalyzingBook;
import utils.LibarySingleton;
import utils.ScannerSingleton;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 殇
 * Date: 2025-07-16
 * Time: 16:19
 */
public class AdminUser extends User{
    private  Scanner sc;
    private Libary libary;
    private AnalyzingBook analyzingBook=new AnalyzingBook();
    public AdminUser(String name, int userId) {
        super(name, userId,"管理员");
        sc= ScannerSingleton.getScanner();
        libary= LibarySingleton.getLibary();
    }



    public void addBook(String bookName){
        System.out.println("管理员"+name+"借阅了"+bookName);
    }
    //管理员菜单
    @Override
    public int display() {
        System.out.println("管理员 " + name + " 的操作菜单:");
        System.out.println("1. 查找图书");
        System.out.println("2. 打印所有的图书");
        System.out.println("3. 退出系统");
        System.out.println("4. 上架图书");
        System.out.println("5. 修改图书");
        System.out.println("6. 下架图书");
        System.out.println("7. 统计借阅次数");
        System.out.println("8. 查看最后欢迎的前K本书");
        System.out.println("9. 查看库存状态");
        System.out.println("10. 检查超过⼀年未下架的图书");
        System.out.println("请选择你的操作：");
        return sc.nextInt();
    }

    //添加书籍
    public void addBook(){
        System.out.println("请输入书名:");
        String tittle=sc.next();
        System.out.println("请输入作者:");
        String author=sc.next();
        System.out.println("请输入类别:");
        String category=sc.next();
        System.out.println("请输入出版年份:");
        int publishYear=sc.nextInt();
        LocalDate shelfDate=LocalDate.now();

        Book book=new Book(tittle,author,category,publishYear,shelfDate);
        libary.addBook(book);
    }

    //更新书籍操作
    public void updateBook() {
        libary.display();
        System.out.println("请输入要修改书籍的Id:");
        int id=sc.nextInt();
        Book book=libary.searchBookId(id);
        if(book!=null){
            System.out.println("请输入书名:");
            String title=sc.nextLine();
            System.out.println("请输入作者:");
            String author=sc.nextLine();
            System.out.println("请输入类别:");
            String category=sc.next();

            book.setTitle(title);
            book.setAuthor(author);
            book.setCategory(category);

            libary.updateBook(book);
        }
        else{
            System.out.println("该书籍Id不存在！！！");
        }
    }

    //移除图书
    public void removeBook() {
        //打印所有书籍
        libary.display();
        System.out.println("请输入删除书籍的Id:");
        int bookId=sc.nextInt();
        sc.nextLine();   //吞掉换行符
        //获取要删除书籍的对象
        Book book=libary.searchBookId(bookId);
        if(book!=null) {
            libary.removeBook(bookId);
            System.out.println("书籍"+book.getTitle()+"已经成功删除!!!");
        }
        else
            System.out.println("书籍不存在，无法删除");
    }
    //查看每本图书的借阅次数
    public void borrowCount( ) {
        libary.borrowCount();
    }
    //查看最受欢迎的前K本书
    public void generateBook() {
        System.out.println("请输入要查看的最受欢迎的前k本书(k不允许超过"+libary.getBookCount()+"):");
        int k=sc.nextInt();
        if(k<=0||k> libary.getBookCount()){
            System.out.println("输入不合法!!!");
            return ;
        }
        libary.generateBook(k);
    }
    //查看库存状态: 显示所有书籍的状态，借出or在存
    public void checkInventoryStatus() {
        libary.checkInventoryStatus();
    }
    //移除上架超过1年的书籍
    public void checkAndRemoveOldBooks() {
        libary.checkAndRemoveOldBooks();
    }


}
